﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using UsernameAssertionLibrary;

using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Design;

namespace Incubator
{
    public partial class register : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void registerButton_Click(object sender, EventArgs e)
        {

            UsernameClientAssertion assert = new UsernameClientAssertion("registration", "regpass");

            // create policy
            Policy policy = new Policy();
            policy.Assertions.Add(assert);
            Global.incuServ.SetPolicy(policy);

            if (userName.Text.Length != 0 && passWord.Text.Equals(confirmPassword.Text))
            {

                webRef.User u = Global.incuServ.RegisterUser(Fname.Text, Lname.Text, userName.Text, passWord.Text, 0);
                if (u.id == -1)
                { //registration failure
                    warningMessage.Text = "Username already exists. Please try a different username.";
                    return;
                }
                Session["User"] = u;
                Session["UserID"] = u.id;

                warningMessage.Text = "Successful Registration!";

                Session["username"] = userName.Text;
                Session["pass"] = passWord.Text;

                Response.Redirect("CreateCompany.aspx");
            }
            else
            {
                warningMessage.Text = "Passwords are not equal!";
            }

            if (userName.Text.Length == 0)
            {
                warningMessage.Text = "Please enter a username!";
            }
            if (passWord.Text.Length == 0)
            {
                 warningMessage.Text = "Please enter a password!";
            }
            if(confirmPassword.Text.Length == 0)
            {
                 warningMessage.Text = "Please confirm the password!";
            }
            if (Fname.Text.Length == 0)
            {
                warningMessage.Text = "Please enter your first name!";
            }
            if (Lname.Text.Length == 0)
            {
                warningMessage.Text = "Please enter your last name!";
            }
        }

        protected void userName_TextChanged(object sender, EventArgs e)
        {

        }

        protected void userName_TextChanged1(object sender, EventArgs e)
        {

        }
    }
}